home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / REVERSE.PAK / REVERSE.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  47 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  REVERSE.CPP                                                           */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1995 Borland International                        */
  6. /*  All Rights Reserved.                                                  */
  7. /*                                                                        */
  8. /*  TStack example file                                                   */
  9. /*                                                                        */
  10. /*------------------------------------------------------------------------*/
  11. #include <classlib/stacks.h>
  12. #include <services/cstring.h>
  13. #include <iostream.h>       
  14.  
  15. int main()
  16. {
  17.     TStack<string> TheStack;
  18.     string Reverse("reverse");
  19.  
  20.     cout << "\nEnter some strings.  Reverse will collect the strings\n";
  21.     cout << "for you until you enter the string \"reverse\".  Reverse\n";
  22.     cout << "will then print out the strings you have entered, but in\n";
  23.     cout << "reverse order.  Begin entering strings now.\n";
  24.  
  25.     for(;;)
  26.         {
  27.         char InputString[255];
  28.         cin >> InputString;
  29.         string NewString( InputString );
  30.         if( NewString != Reverse )
  31.             {
  32.             TheStack.Push( NewString );
  33.             }
  34.         else 
  35.             {
  36.             break;
  37.             }
  38.         }
  39.  
  40.     cout << "\nThe strings you entered (if any) are:\n";
  41.     while( !(TheStack.IsEmpty()) )
  42.         {
  43.         cout << TheStack.Pop() << endl;
  44.         }
  45.     return 0;
  46. }
  47.